<?php
class PlacementsController extends AppController {

	var $name = 'Placements';

	function index() {
               $this->set('title_for_layout', 'Datos judiciales - Circunscripciones');
		$this->Placement->recursive = 0;
		$this->set('placements', $this->paginate());
	}

	function view($id = null) {
            $this->loadModel('Charter');
            $this->set('title_for_layout', 'Datos judiciales - Circunscripciones');
		if (!$id) {
			$this->Session->setFlash(__('Invalid placement', true));
			$this->redirect(array('action' => 'index'));
		}

		$this->set('placement', $this->Placement->read(null,$id));
             	}

	function add() {
            $this->set('title_for_layout', 'Datos judiciales - Circunscripciones');
            $this->loadModel('Province');
		if (!empty($this->data)) {
			$this->Placement->create();
			if ($this->Placement->save($this->data)) {
				$this->Session->setFlash(__('The placement has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The placement could not be saved. Please, try again.', true));
			}
		}
                $provinces = $this->Province->find('list');
		$charters = $this->Placement->Charters->find('list',array('fields'=>'descripcion'));
		
                $this->set(compact('charters','provinces'));
	}
        
	function edit($id = null) {
            $this->set('title_for_layout', 'Datos judiciales - Circunscripciones');
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid placement', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Placement->save($this->data)) {
				$this->Session->setFlash(__('The placement has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The placement could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Placement->read(null, $id);
		}
		$charters = $this->Placement->Charters->find('list',array('fields'=>'descripcion'));
		$this->set(compact('charters'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for placement', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Placement->delete($id)) {
			$this->Session->setFlash(__('Placement deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Placement was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
